/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PYMETADATA_GC_HH
#define PYMETADATA_GC_HH
//! \addtogroup python_backend
//@{

// INCLUDES
#include <Python.h>
#include "util.hh"

// DECLARATIONS
class python_metadata;

// CLASS

class pymetadata_gc
{
    struct node_str
    {
	python_metadata *obj;  // take a reference
	node_str **ref;        // python objects refering this one
	int n_ref, max_ref;
	bool used;

	node_str(python_metadata *obj);
	~node_str();

	// returns true if referer already in ref list
	bool check_referer(node_str *referer);
	void add_referer(node_str *referer);
    } **node;
    int n_node, max_node;

    // PRIVATE METHODS
    bool create_graph_recur(node_str *node, node_str *referer);
    bool create_graph_list_recur(PyObject *list, node_str *referer);

    node_str *search_obj(python_metadata *obj);
    int search_ref(node_str *from_me, int from=0); // search objects referenced from_me

    void debug_recur(node_str *node, int tab);

public:
    pymetadata_gc();
    ~pymetadata_gc();

    bool add(python_metadata *obj);

    void debug();
};

//@}
#endif

/* Offline metadata attributes:

   @metadata_attrs(
	pymetadata_gc:
					~select
   )
*/
